let NewSrcTemplate="ClassTemplate.cpp"
let NewHdrTemplate="ClassTemplate.h"

fu! NewClass(ClassName)
	let Macro = substitute(a:ClassName, '::', '_', 'g') . '_h'
	let ClassHdr = substitute(a:ClassName, '::', '/', 'g') . '.h'
	let ClassSrc = substitute(a:ClassName, '::', '/', 'g') . '.cpp'
	let Ns2 = substitute(substitute(a:ClassName, '^[^:]*::', '', ''), '::.*$', '', '')
	let ClassName = substitute(a:ClassName, '^.*::', '', '')

	let Dir = substitute(ClassSrc, '/[^/]\+$', '', '')
	if !isdirectory(Dir)
		call mkdir(Dir,'p')
	endif

	tabnew
	exe "vi " . ClassSrc 
	exe "0r " . g:NewSrcTemplate
	exe "%s/%ClassName%/" . ClassName . "/ge"
	exe "%s/%Ns2%/" . Ns2 . "/ge"
	exe "vert new " . ClassHdr
	exe "0r " . g:NewHdrTemplate
	exe "%s/%ClassName%/" . ClassName . "/ge"
	exe "%s/%CLASS_NAME%/" . Macro . "/ge"
	exe "%s/%Ns2%/" . Ns2 . "/ge"
endf

command! -nargs=1 NewClass call NewClass(<q-args>)


